/*   Shotscreens
 *   Copyright (C) 2011, Andrew Lisin (http://crystalnix.com)
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TRAY_H
#define TRAY_H

#include "globalshortcut.h"
#include <QByteArray>
#include <QMenu>
#include <QPixmap>
#include <QSystemTrayIcon>

/* I think we can move this class into QT_NAMESPACE,
 * but there is no problem for now and I don't want to
 * repair something that hasn't broken down.
 */
class FullscreenWidget;
class SettingsMenu;

QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE

/* The Tray class is representing icon in system tray
 * and communicates all shotscreens elements such as
 * selecting widget, screenshot editor and settings menu.
 */

class Tray : public QSystemTrayIcon
{
    Q_OBJECT
    Q_PROPERTY(bool active READ isActive WRITE setActive) // property that used for store state whether
                                                          // shortcut is active.

public:
    explicit Tray(QObject *parent = 0);

    /* Actions that will be in the tray in oreder they should be in tray  */
    QAction *activityAction; // start or stop
    QAction *captureAction;
    QAction *settingsAction;
    QAction *separator;
    QAction *change_account;
    QAction *quitAction;

    QMenu menu; // menu where we put all actions

private:
    // active property and its methods:
    bool active;
    bool isActive() const;
    void setActive(bool);

    bool lock;

    GlobalShortcut shortcut;


    FullscreenWidget* fullscreenwidget; // selecting mode widget
    SettingsMenu* settingsMenu; // settings menu widget

    void createMenu();
    void createTray(); // creates tray icon

    void initializeTray(); // initialize all nessesary connections.
                           // The connections that may not be used
                           // are initialized in place.

    void initializeShortcut(); // get shortcut key from settings.

public slots:
    void takeScreenshot(); // call this slot, when you want to get a screenshot.
    void startEditor(QPixmap); // calls after we have got a screenshot.
    void uploadData(QByteArray); // calls after we efit our screenshot anв ready to send it.
    void changeAccount();

private slots:
    void changeActivity(); // set/unset taking screenshot with shortcut.
    void openSettingsMenu();
    void changeHotkey(QKeySequence key);
    void nullSettingsMenuPtr();
    void nullFullScrPtr();

};

#endif // TRAY_H
